package com.jack.payment.controller.admin.auth;

import com.jack.payment.annotation.PagingLimit;
import com.jack.payment.entity.common.BusinessException;
import com.jack.payment.entity.common.CommonAskParam;
import com.jack.payment.entity.common.CommonResult;
import com.jack.payment.entity.filter.UserFilter;
import com.jack.payment.entity.generate.user.UserApiModel;
import com.jack.payment.entity.generate.user.UserDeviceModel;
import com.jack.payment.entity.generate.user.UserModel;
import com.jack.payment.entity.result.PageVo;
import com.jack.payment.service.basic.impl.UserMessageServiceImpl;
import com.jack.payment.util.common.PageResultUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@Tag(name = "用户其他信息")
@RequestMapping("/api/v1/userMessage")
public class UserMessageController {
    private Logger log = LoggerFactory.getLogger(UserMessageController.class);

    @Autowired
    private UserMessageServiceImpl userMessageService;
    @Autowired
    private PageResultUtil pageResultUtil;


    @Operation(summary = "获取用户的设备信息列表")
    @RequestMapping(value = "getAppointUserDeviceList", method = {RequestMethod.POST})
    @ResponseBody
    @PagingLimit
    public CommonResult getAppointUserDeviceList(@RequestBody CommonAskParam<UserFilter.UserDeviceFilter> data) throws BusinessException {
        UserModel userModel = (UserModel) data.getCommon().getUserId();
        UserFilter.UserDeviceFilter requestParam = data.getData();
        requestParam.setUserId(userModel.getId());

        Integer resultCount = userMessageService.getAppointUserDeviceCount(requestParam);
        // 判断数据是否超出
        pageResultUtil.judgeRequestCount(
                requestParam.getPage(),
                resultCount
        );
        List<UserDeviceModel> pageList = userMessageService.getAppointUserDeviceList(requestParam);
        return CommonResult.ok(new PageVo<UserDeviceModel>(
                pageList,
                pageResultUtil.resultPageComputer(requestParam.getCount(), resultCount),
                requestParam.getPage() / requestParam.getCount()));
    }

    @Operation(summary = "调用api 的列表")
    @RequestMapping(value = "getAppointUserApiKeyList", method = { RequestMethod.POST })
    @ResponseBody
    public CommonResult getAppointUserApiKeyList(@RequestBody @Validated CommonAskParam<UserFilter.UserApiFilter> data) throws BusinessException {
        UserModel userModel = (UserModel) data.getCommon().getUserId();
        UserFilter.UserApiFilter requestParam = data.getData();
        Integer resultCount = userMessageService.getUserApiModelCount(requestParam);
        // 判断数据是否超出
        pageResultUtil.judgeRequestCount(
                requestParam.getPage(),
                resultCount
        );
        List<UserApiModel> pageList = userMessageService.getUserApiModelList(requestParam);
        return CommonResult.ok(new PageVo<UserApiModel>(
                pageList,
                pageResultUtil.resultPageComputer(requestParam.getCount(), resultCount),
                requestParam.getPage() / requestParam.getCount()));
    }

    @Operation(summary = "用户各钱包信息")
    @RequestMapping(value = "getAppointUserWalletList", method = { RequestMethod.POST})
    @ResponseBody
    public CommonResult getAppointUserWalletList() {
        return CommonResult.ok();
    }

    @Operation(summary = "获取用户消息列表")
    @RequestMapping(value = "getAppointUserMessageList", method = {RequestMethod.POST})
    @ResponseBody
    public CommonResult getAppointUserMessage() {
        return CommonResult.ok();
    }
}
